<?php
/**
 * Created by PhpStorm.
 * User: Loong
 * Date: 2021/8/28
 * Time: 8:41
 */
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;
use think\facade\View;

class Brand
{
    public function brandList()
    {

        $post = Request::get();

        $where = [];
        $whereOr = [];
        if (isset($post['keywords']) && !empty($post['keywords']))      $where[] = ['brand_name','like',"%{$post['keywords']}%"];
        if (isset($post['recommended']) && $post['recommended'] <> '')  $where[] = ['recommended','=',$post['recommended']];
        if (isset($post['if_show']) && count($post['if_show']) == 1)         $where[] = ['if_show','in',$post['if_show']];
        if (isset($post['if_img']) && count($post['if_img']) == 1) {
            if ($post['if_img'][0] == 0){
                $whereOr[] = ['brand_logo','=',''];
                $whereOr[] = ['brand_logo','=',null];
            }
            if ($post['if_img'][0] == 1) $where[] = ['brand_logo','<>',''];
        }
        View::assign($post);
        unset($post['order']);
        //查询品牌数据
        $list = Db::name('brand')
            ->where($where)
            ->whereOr($whereOr)
            ->field(true)
            ->order('sort_order','asc')
            ->paginate([
                'list_rows' => 5,
                'query'     => $post
            ]);
        //发送数据到视图
        View::assign('list',$list);
        //渲染模板视图
        return view();
    }





}